﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Xml;

namespace CommonFunction
{
    public static class Extension
    {
        //get RouletteURL
        public static string GetRouletteURL(this XmlDocument xmlDoc)
        {
            return xmlDoc.FirstChild.FirstChild.FirstChild.InnerText;
        }

        //set RouletteURL
        public static void SetRouletteURL(this XmlDocument xmlDoc, string newValue)
        {
            xmlDoc.FirstChild.FirstChild.FirstChild.InnerText = newValue;
        }

        //get RoulettistName
        public static string GetRoulettistName(this XmlDocument xmlDoc)
        {
            return xmlDoc.FirstChild.FirstChild.FirstChild.NextSibling.InnerText;
        }

        //set RoulettistName
        public static void SetRoulettistName(this XmlDocument xmlDoc, string newValue)
        {
            xmlDoc.FirstChild.FirstChild.FirstChild.NextSibling.InnerText = newValue;
        }

        //get BetRate
        public static string GetBetRate(this XmlDocument xmlDoc)
        {
            return xmlDoc.FirstChild.FirstChild.NextSibling.FirstChild.InnerText;
        }

        //set BetRate
        public static void SetBetRate(this XmlDocument xmlDoc, string newValue)
        {
            xmlDoc.FirstChild.FirstChild.NextSibling.FirstChild.InnerText = newValue;
        }

        //get StopWinning
        public static string GetStopWinning(this XmlDocument xmlDoc)
        {
            return xmlDoc.FirstChild.FirstChild.NextSibling.FirstChild.NextSibling.InnerText;
        }

        //set StopWinning
        public static void SetStopWinning(this XmlDocument xmlDoc, string newValue)
        {
            xmlDoc.FirstChild.FirstChild.NextSibling.FirstChild.NextSibling.InnerText = newValue;
        }

        //get StopLosing
        public static string GetStopLosing(this XmlDocument xmlDoc)
        {
            return xmlDoc.FirstChild.FirstChild.NextSibling.FirstChild.NextSibling.NextSibling.InnerText;
        }

        //set StopLosing
        public static void SetStopLosing(this XmlDocument xmlDoc, string newValue)
        {
            xmlDoc.FirstChild.FirstChild.NextSibling.FirstChild.NextSibling.NextSibling.InnerText = newValue;
        }

        //get DoItFollowing
        public static string GetDoItFollowing(this XmlDocument xmlDoc)
        {
            return xmlDoc.FirstChild["Configuration"]["Following"]["DoIt"].InnerText;
        }

        //set DoItFollowing
        public static void SetDoItFollowing(this XmlDocument xmlDoc, string newValue)
        {
            xmlDoc.FirstChild["Configuration"]["Following"]["DoIt"].InnerText = newValue;
        }

        //get Following Black/Red Values
        public static XmlNode GetFollowingBlackRedValues(this XmlDocument xmlDoc)
        {
            return xmlDoc.FirstChild["Configuration"]["Following"]["BlackRed"];
        }

        //set Following Black/Red Values
        public static void SetFollowingBlackRedValues(this XmlDocument xmlDoc, string[] newValues)
        {
            var Nodes = xmlDoc.FirstChild["Configuration"]["Following"]["BlackRed"].ChildNodes;
            for (int i = 0; i < newValues.Length; i++)
            {   
                Nodes[i].InnerText = newValues[i];
            }
        }

        //get Following High/Low Values
        public static XmlNode GetFollowingHighLowValues(this XmlDocument xmlDoc)
        {
            return xmlDoc.FirstChild["Configuration"]["Following"]["HighLow"];
        }

        //set Following High/Low Values
        public static void SetFollowingHighLowValues(this XmlDocument xmlDoc, string[] newValues)
        {
            var Nodes = xmlDoc.FirstChild["Configuration"]["Following"]["HighLow"].ChildNodes;
            for (int i = 0; i < newValues.Length; i++)
            {
                Nodes[i].InnerText = newValues[i];
            }
        }

        //get Following Even/Odd Values
        public static XmlNode GetFollowingEvenOddValues(this XmlDocument xmlDoc)
        {
            return xmlDoc.FirstChild["Configuration"]["Following"]["EvenOdd"];
        }

        //set Following Even/Odd Values
        public static void SetFollowingEvenOddValues(this XmlDocument xmlDoc, string[] newValues)
        {
            var Nodes = xmlDoc.FirstChild["Configuration"]["Following"]["EvenOdd"].ChildNodes;
            for (int i = 0; i < newValues.Length; i++)
            {
                Nodes[i].InnerText = newValues[i];
            }
        }

        //get Other Black-Red Values
        public static XmlNode GetBlackRedValues(this XmlDocument xmlDoc)
        {
            return xmlDoc.FirstChild["Configuration"]["Others"]["BlackRed"];
        }

        //set Other Following Values
        public static void SetBlackRedValues(this XmlDocument xmlDoc, string[] newValues)
        {
            var Nodes = xmlDoc.FirstChild["Configuration"]["Others"]["BlackRed"].ChildNodes;
            for (int i = 0; i < newValues.Length; i++)
            {
                Nodes[i].InnerText = newValues[i];
            }
        }

        //get Other Even-Odd Values
        public static XmlNode GetEvenOddValues(this XmlDocument xmlDoc)
        {
            return xmlDoc.FirstChild["Configuration"]["Others"]["EvenOdd"];
        }

        //set Other Even-Odd Values
        public static void SetEvenOddValues(this XmlDocument xmlDoc, string[] newValues)
        {
            var Nodes = xmlDoc.FirstChild["Configuration"]["Others"]["EvenOdd"].ChildNodes;
            for (int i = 0; i < newValues.Length; i++)
            {
                Nodes[i].InnerText = newValues[i];
            }
        }

        //get Other High-Low Values
        public static XmlNode GetHighLowValues(this XmlDocument xmlDoc)
        {
            return xmlDoc.FirstChild["Configuration"]["Others"]["HighLow"];
        }

        //set Other High-Low Values
        public static void SetHighLowValues(this XmlDocument xmlDoc, string[] newValues)
        {
            var Nodes = xmlDoc.FirstChild["Configuration"]["Others"]["HighLow"].ChildNodes;
            for (int i = 0; i < newValues.Length; i++)
            {
                Nodes[i].InnerText = newValues[i];
            }
        }

        //get Other Columns Values
        public static XmlNode GetColumnValues(this XmlDocument xmlDoc)
        {
            return xmlDoc.FirstChild["Configuration"]["Others"]["Columns"];
        }

        //set Other Columns Values
        public static void SetColumnValues(this XmlDocument xmlDoc, string[] newValues)
        {
            var Nodes = xmlDoc.FirstChild["Configuration"]["Others"]["Columns"].ChildNodes;
            for (int i = 0; i < newValues.Length; i++)
            {
                Nodes[i].InnerText = newValues[i];
            }
        }

        //get Other Dozens Values
        public static XmlNode GetDozenValues(this XmlDocument xmlDoc)
        {
            return xmlDoc.FirstChild["Configuration"]["Others"]["Dozens"];
        }

        //set Other Dozens Values
        public static void SetDozenValues(this XmlDocument xmlDoc, string[] newValues)
        {
            var Nodes = xmlDoc.FirstChild["Configuration"]["Others"]["Dozens"].ChildNodes;
            for (int i = 0; i < newValues.Length; i++)
            {
                Nodes[i].InnerText = newValues[i];
            }
        }

        //get Other Numbers Values
        public static XmlNode GetNumberValues(this XmlDocument xmlDoc)
        {
            return xmlDoc.FirstChild["Configuration"]["Others"]["Numbers"];
        }

        //set Other Numbers Values
        public static void SetNumberValues(this XmlDocument xmlDoc, string[] newValues)
        {
            var Nodes = xmlDoc.FirstChild["Configuration"]["Others"]["Numbers"].ChildNodes;
            for (int i = 0; i < newValues.Length; i++)
            {
                Nodes[i].InnerText = newValues[i];
            }
        }

        //get Poker name
        public static string GetPokerName(this XmlDocument xmlDoc)
        {
            return xmlDoc.FirstChild["name"].InnerText;
        }

        //set Poker name
        public static void SetPokerName(this XmlDocument xmlDoc, string pokerName)
        {
            xmlDoc.FirstChild["name"].InnerText = pokerName;
        }

        //get Poker email
        public static string GetPokerEmail(this XmlDocument xmlDoc)
        {
            return xmlDoc.FirstChild["email"].InnerText;
        }

        //set Poker email
        public static void SetPokerEmail(this XmlDocument xmlDoc, string email)
        {
            xmlDoc.FirstChild["email"].InnerText = email;
        }

        //get Poker password
        public static string GetPokerPassword(this XmlDocument xmlDoc)
        {
            return xmlDoc.FirstChild["password"].InnerText;
        }

        //set Poker password
        public static void SetPokerPassword(this XmlDocument xmlDoc, string password)
        {
            xmlDoc.FirstChild["password"].InnerText = password;
        }

        //get Poker role
        public static int GetPokerRole(this XmlDocument xmlDoc)
        {
            return Convert.ToInt32(xmlDoc.FirstChild["role"].InnerText);
        }

        //set Poker role
        public static void SetPokerRole(this XmlDocument xmlDoc, Int32 role)
        {
            xmlDoc.FirstChild["role"].InnerText = role.ToString();
        }

        //get Poker amount
        public static int GetPokerAmount(this XmlDocument xmlDoc)
        {
            return Convert.ToInt32(xmlDoc.FirstChild["amount"].InnerText);
        }

        //set Poker amount
        public static void SetPokerAmount(this XmlDocument xmlDoc, Int32 amount)
        {
            xmlDoc.FirstChild["amount"].InnerText = amount.ToString();
        }

        //get Poker raise
        public static int GetPokerRaise(this XmlDocument xmlDoc)
        {
            return Convert.ToInt32(xmlDoc.FirstChild["raise"].InnerText);
        }

        //set Poker raise
        public static void SetPokerRaise(this XmlDocument xmlDoc, Int32 raise)
        {
            xmlDoc.FirstChild["raise"].InnerText = raise.ToString();
        }

        //get number of turns to fold
        public static int GetTurnFold(this XmlDocument xmlDoc)
        {
            return Convert.ToInt32(xmlDoc.FirstChild["turnFold"].InnerText);
        }

        //set number of turns to fold
        public static void SetTurnFold(this XmlDocument xmlDoc, Int32 noOfTurnToFold)
        {
            xmlDoc.FirstChild["turnFold"].InnerText = noOfTurnToFold.ToString();
        }

        //get call any
        public static bool GetCallAny(this XmlDocument xmlDoc)
        {
            return Convert.ToBoolean(xmlDoc.FirstChild["callAny"].InnerText);
        }

        //set call any
        public static void SetCallAny(this XmlDocument xmlDoc, bool callAny)
        {
            xmlDoc.FirstChild["callAny"].InnerText = callAny.ToString();
        }

        //compare 2 image
        public static bool EqualTo(this Image source, Image target)
        {   
            if (source.Size != target.Size) return false;

            var src = new System.IO.MemoryStream();
            source.Save(src, System.Drawing.Imaging.ImageFormat.Jpeg);

            var tg = new System.IO.MemoryStream();
            target.Save(tg, System.Drawing.Imaging.ImageFormat.Jpeg);

            string firstImage = Convert.ToBase64String(src.ToArray());
            string secondImage = Convert.ToBase64String(tg.ToArray());

            src = null;
            tg = null;

            return firstImage.Equals(secondImage);
        }
    }
}
